home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / GENCSRC.ZIP / MACRO.C < prev    next >
C/C++ Source or Header  |  1987-11-21  |  924b  |  27 lines

  1.                                         /* Chapter 6 - Program 2 */
  2. #define WRONG(A) A*A*A          /* Wrong macro for cube     */
  3. #define CUBE(A) (A)*(A)*(A)     /* Right macro for cube     */
  4. #define SQUR(A) (A)*(A)         /* Right macro for square   */
  5. #define ADD_WRONG(A) (A)+(A)    /* Wrong macro for addition */
  6. #define ADD_RIGHT(A) ((A)+(A))  /* Right macro for addition */
  7. #define START 1
  8. #define STOP  7
  9.  
  10. main()
  11. {
  12. int i,offset;
  13.  
  14.    offset = 5;
  15.    for (i = START;i <= STOP;i++) {
  16.       printf("The square of %3d is %4d, and its cube is %6d\n",
  17.               i+offset,SQUR(i+offset),CUBE(i+offset));
  18.       printf("The wrong of  %3d is %6d\n",i+offset,WRONG(i+offset));
  19.    }
  20.  
  21.    printf("\nNow try the addition macro's\n");
  22.    for (i = START;i <= STOP;i++) {
  23.       printf("Wrong addition macro = %6d, and right = %6d\n"
  24.                                ,5*ADD_WRONG(i),5*ADD_RIGHT(i));
  25.    }
  26. }
  27.